﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Lyon.Register
{
    [Serializable]
    class RegisterInfo
    {
        public string UserName { get; set; }
        public string AppName { get; set; }
        public bool IsEnableMachineCode { get; set; }
        public string MachineCode { get; set; }
        public bool IsEnableLimit { get; set; }
        public DateTime Limit { get; set; }
        public DateTime LastVisitDate { get; set; }

        static public string GetStr(RegisterInfo value)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                System.Runtime.Serialization.Formatters.Binary.BinaryFormatter temp = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                temp.Serialize(stream, value);
                return Convert.ToBase64String(stream.ToArray());
            }
        }

        static public RegisterInfo GetInfo(string value)
        {
            using (MemoryStream stream = new MemoryStream(Convert.FromBase64String(value)))
            {
                System.Runtime.Serialization.Formatters.Binary.BinaryFormatter temp = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                return (RegisterInfo)temp.Deserialize(stream);
            }
        }
    }
}
